<div class="sidebar">

    {% if user.is_authenticated %}
        <!--最近浏览-->
        <div class="bg-white p-4 mb-2">
            <h3 class="border-bottom text-muted shadow-sm">最近浏览</h3>

            {% for post in recent_visited_posts %}
            <div class="mb-2">
                <a href="{{ post.get_absolute_url }}" class="text-decoration-none text-weight-bold text-dark">{{ post.title }}</a>
            </div>
            {% empty %}
            <p class="text-muted">无历史浏览记录</p>
            {% endfor %}
        </div>

        <div class="bg-white p-4 mb-2">
            <h3 class="border-bottom text-muted shadow-sm">文章分类</h3>

            {% for item in category_with_post_count %}
                <div class="mb-2">
                    <a href="{% url 'blog:category_posts' item.name %}" class="text-decoration-none text-weight-bold text-dark">{{ item.name }}</a> ({{ item.post_count }})
                </div>
                {% empty %}
                <p class="text-muted">还没有类别</p>
            {% endfor %}
        </div>
    {% endif %}

    <!--热门文章-->
    <div class="bg-white p-4 mb-2">
        <h3 class="border-bottom text-muted shadow-sm">热门文章</h3>
        {% if popular_posts %}
            {% for post in popular_posts %}
            <div class="mb-2">
                <a href="{{ post.get_absolute_url }}" class="text-decoration-none text-weight-bold text-dark">{{ post.title }}</a>
            </div>
            <small class="text-muted">阅读: {{ post.num_views }}</small>
            {% endfor %}
        {% endif %}
    </div>

    {% if user.is_authenticated %}
        <!--归档-->
        <div class="bg-white p-4">
            <h3 class="border-bottom text-muted shadow-sm">归档</h3>
            {% if post_archives %}
                {% for item in post_archives %}
                <div class="mb-2">
                    <a href="{% url 'blog:month_archive' item.year_month %}" class="text-decoration-none text-weight-bold text-dark">{{ item.year_month }}</a>
                    <small class="text-muted">({{ item.post_count }})</small>
                </div>
                {% endfor %}
            {% endif %}
        </div>
    {% endif %}
</div>
